package com.game.doudizhu.task;

import com.game.doudizhu.service.GameRoomService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class RoomCleanupTask {
    
    private static final Logger logger = LoggerFactory.getLogger(RoomCleanupTask.class);
    
    @Autowired
    private GameRoomService gameRoomService;
    
    // 每5分钟执行一次清理
    @Scheduled(fixedRate = 300000)
    public void cleanupRooms() {
        logger.info("开始清理房间...");
        try {
            int cleanedCount = gameRoomService.cleanupInactiveRooms();
            logger.info("房间清理完成，共清理 {} 个房间", cleanedCount);
        } catch (Exception e) {
            logger.error("房间清理失败", e);
        }
    }
} 